(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.currency.deleteController', deleteController);
	deleteController.$inject = [ '$scope', 'Constants', 'modalService', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'currencyService' ];
	function deleteController($scope, Constants, modalService, layoutConfig, validatorConfig, gridService, authService, currencyService) {
		var ctrl = this, currencyInfo = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.currency = {};
		ctrl.init = function() {
			var params = {
				ccy : currencyInfo.ccy
			};
			authService.delete(params).then(function(response) {
				ctrl.currency = response.data || currencyInfo;
				currencyService.getCountryOptions().then(function(response) {
					ctrl.countryCodeOptions = response;
				}, function(error) {
					log.debug('can\'t load country code options' + angular.toJson(error));
				});
				currencyService.getIntCalcBasisOptions().then(function(response) {
					ctrl.calbaseOptions = response;
				}, function(error) {
					log.debug('can\'t load interest calc options' + angular.toJson(error));
				});	
				
				ctrl.decimalNumOption = getDecimalNumOption();
				
			});
		};
		
		function getDecimalNumOption() {
			var option = {
					"data" : [
					 {
						"value" : 1,
						"label" : 1
					}, {
						"value" : 2,
						"label" : 2
					}, {
						"value" : 3,
						"label" : 3
					} ]
			};
			return option;
		};
		
		ctrl.deleteCurrency = function() {
			modalService.openConfirmDialogs({
				'messages' : [ {msg : 'title.dialog.confirm.delete', args : [ctrl.currency.primaryKey]} ],
				'btnCallback' : {
					'ok' : function(response) {
						authService.deleteSubmit(ctrl.currency).then(deleteSuccessful, deleteFailed);
					}
				}
			});
		};
		
		function deleteSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.delete' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('cda.currency.list');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.workflow.list',
					'state' : 'cda.workflow.wfSetup.list',
					'params' : {}
				}, {
					'name' : 'title.infobar.currency.list',
					'state' : 'cda.currency.list',
					'params' : {}
				}]
			});
//			ctrl.currency = response.data;
		}

		function deleteFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}
	}
})(angular);
